<%
# Copyright (C) 2012 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<div>
  <%= external_tools_menu_items(@course_settings_sub_navigation_tools, {link_class: "Button Button--link Button--link--has-divider Button--course-settings course-settings-sub-navigation-lti", settings_key: :course_settings_sub_navigation}) %>
  <% if can_do(@context, @current_user, :use_student_view) %>
    <%= link_to course_student_view_path(@context), :method => :post, :class => 'Button Button--link Button--link--has-divider Button--course-settings student_view_button' do %>
      {{> icons/student-view}}{{#t}}Student View{{/t}}
    <% end %>
  <% end %>

  <% if can_do(@context, @current_user, :read_reports) %>
    <%= link_to context_url(@context, :context_statistics_url), :class => ' Button Button--link Button--link--has-divider Button--course-settings' do %>
      {{> icons/stats}}{{#t}}Course Statistics{{/t}}
    <% end %>
  <% end %>

  <% if can_do(@context, @current_user, :read) %>
    <%= link_to calendar_url_for(@context), :class => 'Button Button--link Button--link--has-divider Button--course-settings', :id => 'course_calendar_link' do %>
      {{> icons/calendar-day}}{{#t}}Course Calendar{{/t}}
    <% end %>
  <% end %>

  <% if can_do(@context, @current_user, :change_course_state) %>
    <% if @context.completed? %>
      <%= form_tag context_url(@context, :context_unconclude_url) do %>
        <button class="Button Button--link Button--link--has-divider Button--course-settings" type="submit">
          {{> icons/add}}{{#t}}Un-Conclude Course{{/t}}
        </button>
      <% end %>
    <% elsif !@context.soft_concluded? %>
      <%= link_to context_url(@context, :context_confirm_action_url, :event => 'conclude'), :class => 'Button Button--link Button--link--has-divider Button--course-settings' do %>
        {{> icons/lock}}{{#t}}Conclude this Course{{/t}}
      <% end %>
    <% end %>
  <% end %>

  <% if can_do(@context, @current_user, :delete) && !@context.deleted? %>
    <%= link_to context_url(@context, :context_confirm_action_url, :event => 'delete'), :class => 'Button Button--link Button--link--has-divider Button--course-settings' do %>
      {{> icons/trash}}{{#t}}Delete this Course{{/t}}
    <% end %>
  <% end %>

  <% if can_do(@context, @current_user, :read) && show_user_create_course_button(@current_user, @context.account) %>
    <%= link_to context_url(@context, :context_start_copy_url), :class => 'Button Button--link Button--link--has-divider Button--course-settings copy_course_link' do %>
      {{> icons/copy-course}}{{#t}}Copy this Course{{/t}}
    <% end %>
  <% end %>

  <% if can_do(@context, @current_user, :manage_content, :manage_files, :manage_quizzes) %>
    <%= link_to context_url(@context, :context_content_migrations_url), :class => 'Button Button--link Button--link--has-divider Button--course-settings import_content' do %>
      {{> icons/upload}}{{#t}}Import Course Content{{/t}}
    <% end %>
  <% end %>

  <% if can_do(@context, @current_user, :read) %>
    <%= link_to context_url(@context, :course_content_exports_url), :class => 'Button Button--link Button--link--has-divider Button--course-settings' do %>
      {{> icons/download}}{{#t}}Export Course Content{{/t}}
    <% end %>
  <% end %>

  <% if can_do(@context, @current_user, :reset_content) %>
    <%= link_to context_url(@context, :course_reset_url), :class => ' Button Button--link Button--link--has-divider Button--course-settings reset_course_content_button' do %>
      {{> icons/reset}}{{#t}}Reset Course Content{{/t}}
    <% end %>

    <div <%= hidden(true) %> id="reset_course_content_dialog">
      <p><%= mt('help.reset_course_content', 'Resetting course content will permanently delete all associated assignments, discussions, quizzes, modules, rubrics, pages, files, learning outcomes, question banks, collaborations, conferences, or any other content. This action is irreversible, and the data *cannot* be recovered. Are you sure you wish to continue?') %></p>

      <%= form_for @context, :url => context_url(@context, :course_reset_url), :html => { :method => :post } do %>
        <div class="button-container">
          <button type="button" class="btn cancel_button">
            {{#t}}Cancel{{/t}}
          </button>
          <button type="submit" class="btn btn-danger submit_button">
            {{#t}}Reset Course Content{{/t}}
          </button>
        </div>
      <% end %>
    </div>
  <% end %>

  <% if can_do(@context, @current_user, :manage_content) %>
    <%= link_to context_url(@context, :course_link_validator_url), :class => 'Button Button--link Button--link--has-divider Button--course-settings validator_link' do %>
      {{> icons/link}}{{#t}}Validate Links in Content{{/t}}
    <% end %>
  <% end %>

  <table class="summary">
    <caption>
      <h3>{{#t}}Current Users{{/t}}</h3>
    </caption>

    <tbody>
      <% @all_roles.each do |base_role| %>
        <tr>
          <td><%= base_role[:plural_label] %>:</td>
          <td><%= n(user_count(base_role[:count])) %></td>
        </tr>
        <% base_role[:custom_roles].each do |cr|
           next if skip_custom_role?(cr)
        %>
          <tr>
            <td>
              <%= cr[:label] %><% if cr[:workflow_state] == 'inactive' %> ({{#t}}inactive{{/t}})<% end %>:
            </td>
            <td><%= n(user_count(cr[:count])) %></td>
          </tr>
        <% end %>
      <% end %>
    </tbody>
  </table>
</div>
